<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>Campaigns History - Magneto, by Protoweb</title>

  {include file="head-common.html"}

  <script src="{views_url}js/lib/flot/jquery.flot.min.js"></script>

</head>

<body>

  {include file="header.html"}

  <div class="main container">

    <h1 class="over-bg antialias-white">History</h1>

    {include file="messages_managment.html"}

    <div class="section">

    <div id="placeholder" class="span10" style="height:300px;"></div>

    <script>
    $(function () {
      //var sent = [[-373597200000, 2642], [-370918800000, 2725], [-368326800000, 2623], [-363056400000, 2341],]; 

      var sent = [ 
                   {foreach from=$campaigns item="campaign"} 
                      [
                        (new Date('{$campaign->sent}')).getTime(),
                        {$campaign->sends_delivered() + $campaign->sends_read()}
                      ], 
                    {/foreach} 
                  ];       

      var read = [ 
                   {foreach from=$campaigns item="campaign"} 
                      [
                        (new Date('{$campaign->sent}')).getTime(),
                        {$campaign->sends_read()}
                      ], 
                    {/foreach} 
                  ];       

      var open = [ 
                   {foreach from=$campaigns item="campaign"} 
                      [
                        (new Date('{$campaign->sent}')).getTime(),
                        {$campaign->sends_read()}
                      ], 
                    {/foreach} 
                  ];     

      var unde = [ 
                   {foreach from=$campaigns item="campaign"} 
                      [
                        (new Date('{$campaign->sent}')).getTime(),
                        {$campaign->sends_bounced() + $campaign->sends_undelivered()}
                      ], 
                    {/foreach} 
                  ];       


      $.plot($("#placeholder"), 
        [
          { data: sent, label: "Sent"},
          { data: read, label: "Read"},
          { data: open, label: "Open"},
          { data: unde, label: "Undelivered"}
        ],
        {
          legend: { position: "ne", margin: [-100, 0] },
          series: { 
            lines: { show: true }, points: { show: true } 
          },
          xaxis: {
            mode: "time",
            timeformat: "%0d/%0m",
            ticks: [
              {foreach from=$campaigns item="campaign"} 
                   (new Date('{$campaign->sent}')).getTime(),
               {/foreach} 
            ]
          }
        }
      );

    });
    </script>

    </div>
    <!-- section -->

    {foreach from=$campaigns item="campaign"}
    <div class="row">

      <h2 class="span12">{$campaign->subject}</h2>
      <div class="span12">Date sent: {$campaign->sent} </div>
      <div class="span2">Sent: {$campaign->sends_delivered() + $campaign->sends_read()} emails </div>
      <div class="span3">Read: {$campaign->sends_read()} different people </div>
      <div class="span2">Open: {$campaign->sends_read()} times </div>
      <div class="span2">Bounced: {$campaign->sends_bounced()} recipients </div>
      <div class="span2">Undelivered: {$campaign->sends_undelivered()} emails </div>

    </div>
    {/foreach}

  </div>
  <!-- main container -->

  {include file="footer.html"}

</body>
</html>